package com.kindness.frate.http.model;

import android.content.Context;

import com.kindness.frate.http.ApiWrapper;
import com.kindness.frate.http.model.callback.Callback;

import java.io.File;

import rx.Subscriber;
import rx.Subscription;

/**
 * Created by chenhongxin on 2017/5/19.
 */

public class UserModel extends BaseModel {

    public UserModel(Context context) {
        super(context);
    }

    /**
     * 登录
     * @param userInfo 用户信息 包括用户名，密码
     * @param callback
     */
    public void login(UserInfo userInfo, final Callback<UserInfo> callback){
        ApiWrapper apiWrapper = new ApiWrapper();
        Subscription subscription = apiWrapper.login(userInfo).subscribe(new Subscriber<UserInfo>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(UserInfo userInfo) {
                callback.onSuccess(userInfo);
            }
        });
        addSubscrebe(subscription);
    }

    /**
     * 上传文件
     * @param uploadFile
     * @param callback
     */
    public void uploadFile(File uploadFile, final Callback<String> callback){
        ApiWrapper apiWrapper = new ApiWrapper();
        Subscription subscription = apiWrapper.uploadFile(uploadFile).subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(String content) {
                callback.onSuccess(content);
            }
        });
        addSubscrebe(subscription);
    }

}
